﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using System8ToyMC;
using Numbers;
using System.Windows.Controls;
using ObjectDirectory;

namespace t_System8ToyMCControls
{
    [TestClass]
    public class t_AlphaUC : PresentationTest
    {
        AlphaUC _val;
        Alpha _alpha;
        Alpha_12 _alpha_12;

        FlavorSample _f1num, _f2num, _f1denom, _f2denom;
        epsilon_12 _eps_1, _eps_2;

        NamedValue _alpha_b, _alpha_c, _alpha_l;
        NamedValue _alpha_cl;
        TextBlock _name;

        [TestInitialize]
        public void SetupAlpha()
        {
            _val = new AlphaUC();
            _alpha = new Alpha();
            _val.AlphaValue = _alpha;

            _f1num = new FlavorSample();
            _f2num = new FlavorSample();
            _f1denom = new FlavorSample();
            _f2denom = new FlavorSample();
            _eps_1 = new epsilon_12(_f1num, _f1denom);
            _eps_2 = new epsilon_12(_f2num, _f2denom);
            _alpha_12 = new Alpha_12(_eps_1, _eps_2);

            _val.Alpha12Value = _alpha_12;

            TestPanel.Children.Add(_val);

            _alpha_b = _val.FindName("NVAlphaB") as NamedValue;
            _alpha_c = _val.FindName("NVAlphaC") as NamedValue;
            _alpha_l = _val.FindName("NVAlphaL") as NamedValue;
            _alpha_cl = _val.FindName("TBAlphaCL") as NamedValue;
            _name = _val.FindName("TBName") as TextBlock;

        }

        [TestMethod]
        public void TestCtor()
        {
        }

        [TestMethod]
        public void TestName()
        {
            _val.AlphaName = "hi there";
            Assert.AreEqual("hi there", _name.Text, "Name wasn't set correctly");
        }

        [TestMethod]
        public void TestFindingSources()
        {
            Assert.IsNotNull(_alpha_b, "could not find alpha b");
            Assert.IsNotNull(_alpha_c, "could not find alpha c");
            Assert.IsNotNull(_alpha_l, "could not find alpha l");
            Assert.IsNotNull(_alpha_cl, "could not find alpha_cl");
        }

        [TestMethod]
        public void TestSettingSources()
        {
            _alpha.alpha_b = 0.5;
            Assert.AreEqual(0.5, _alpha_b.Value, "alpha b is not wired correctly");

            _alpha.alpha_c = 0.6;
            Assert.AreEqual(0.6, _alpha_c.Value, "alpha c is not wired correctly");

            _alpha.alpha_l = 0.7;
            Assert.AreEqual(0.7, _alpha_l.Value, "alpha l is not wired correctly");

            _f1num.Charm = 100;
            _f1denom.Charm = 200;
            _f2num.Charm = 100;
            _f2denom.Charm = 200;

            Assert.AreEqual(1.0, _alpha_cl.Value, "Alpha CL is not wired correctly");
        }

        [TestMethod]
        public void TestSettingValues()
        {
            _alpha_b.Value = 0.3;
            Assert.AreEqual(0.3, _alpha.alpha_b, "We aren't getting back the b");
            _alpha_c.Value = 0.4;
            Assert.AreEqual(0.4, _alpha.alpha_c, "We aren't getting back the c");
            _alpha_l.Value = 0.45;
            Assert.AreEqual(0.45, _alpha.alpha_l, "We aren't getting back the l");
        }

        public class alphaHolder
        {
            public Alpha a { get; set; }
            public Alpha_12 a_cl { get; set; }
        }

        [TestMethod]
        public void TestPath()
        {
            FlavorSample f1 = new FlavorSample();
            FlavorSample f2 = new FlavorSample();
            epsilon_12 top = new epsilon_12(f1, f2);
            epsilon_12 eDenom = new epsilon_12(f1, f2);
            alphaHolder ah = new alphaHolder() { a = new Alpha(), a_cl = new Alpha_12(top, eDenom) };

            _val.Path = "a";
            Assert.AreEqual("a", _val.Path, "Didn't remember the straight up path!");

            ObjectPathManager mgr = new ObjectPathManager();

            Assert.AreEqual(mgr.GetPath(ah, ah.a.alpha_bValue), _alpha_b.Path, "The value of the path for b isn't right");
            Assert.AreEqual(mgr.GetPath(ah, ah.a.alpha_cValue), _alpha_c.Path, "The value of the path for c isn't right");
            Assert.AreEqual(mgr.GetPath(ah, ah.a.alpha_lValue), _alpha_l.Path, "The value of the path for l isn't right");
            Assert.AreEqual(mgr.GetPath(ah, ah.a_cl.ValueValue), _alpha_cl.Path, "The value of the path for cl isn't right");
        }
    }
}